home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.0 KB | 67 lines | [TEXT/ttxt] |
- --<<<-
- -- Filename:
- -- mywin.sx
-
- -- Purpose:
- -- Defines the class MyWindowClass.
- -- Provides an implementation for printWindow that renders the presenters
- -- directly to the Printer.
- class MyWindowClass (Window)
- end
-
- method printWindow self {class MyWindowClass} -> (
- local p, scaleFactor, oldRate, tmpArray, tmpSpace
-
- -- Create a Printer
- p := new PrinterSpace
-
- -- We calculate the ratio of our width and height to
- -- that of the Printer.The minimum of the two ratios
- -- is what we'll use to scale our bitmap.
- scaleFactor := min (p.boundary.width / self.boundary.width) \
- (p.boundary.height / self.boundary.height)
-
- -- Create a GroupPresenter to hold the items in our window
- -- The transform goes on the GroupPresenter.
- tmpSpace := new GroupPresenter
- scale tmpSpace.transform scaleFactor scaleFactor
- prepend p tmpSpace
-
- -- This array holds all the items in our window. It
- -- needs to be around since we can't do:
- -- for i in self do
- -- prepend p i
- -- This is because we can't iterate over the items
- -- in the window while we're deleting them from it.
- tmpArray := new Array
- for i in self do
- append tmpArray i
-
- -- Bring up the printer dialog and see if we should continue
- if (printerDialog p) do (
- -- Stop the window's clock so we know nothing will change
- oldRate := self.clock.rate
- self.clock.rate := 0
- self.compositor.enabled := false
-
- -- Move everything over to the Printer
- for i in tmpArray do
- prepend tmpSpace i
-
- -- Take a snapshot of the presentation
- printFrame p
-
- -- Put everything back
- for i in tmpArray do
- prepend self i
-
- -- Restart the window's clock and re-enable the compositor
- self.compositor.enabled := true
- self.clock.rate := oldRate
-
- -- Flush the document
- flushDocument p
- )
- )
- -->>>
-